#ifndef __MINIUTIL_SOCKETCMN_H__
#define __MINIUTIL_SOCKETCMN_H__

#include "os_compatible.h"
#include <string>
#include <vector>

namespace miniutil { namespace socketcmn {

	const int SOCCM_NONBLOCK = 0;
	const int SOCCM_BLOCK = 1;
	const int SOCCM_INVALID_IP = -1;
	const int SOCCM_PRIVATE_IP = 0;
	const int SOCCM_PUBLIC_IP = 1;

	int set_block_mode(SOCKET fd, int block);
    int set_recv_buf(SOCKET fd, int bufsize);
    int set_send_buf(SOCKET fd, int bufsize);
	int is_public_ip(struct sockaddr_in* paddr);
	int is_public_ip(unsigned int ip);
    std::string inet_ntoa_safe(struct in_addr in);
    std::string ip_i2s(struct sockaddr_in);
	std::string ip_i2s(unsigned int ip, unsigned short port);
	int check_cursoc_error();
    std::string get_soc_errorstr(int err);
	SOCKET try_connect(std::string ipstring, int block = 0);
	SOCKET try_connect(struct sockaddr_in *paddr, int block = 0);
	SOCKET try_listen(unsigned short port, int block);

    int getalllocalips(std::vector<struct in_addr>&);
} }

#endif
